package view.PlantUml;

import java.util.ArrayList;
import java.util.Map;

import view.interfaces.Iview;

import Model.Association;
import Model.Classe;
import Model.diagram.ClassDiagram;
import Model.interfaces.Iassociation;
import Model.interfaces.Idiagrame;

public class PlantUmlClassDiagrame  implements Iview{
	private ClassDiagram dia;
	 private String source="";
	@Override
	public void addDiagram(Idiagrame diagram) {
		this.setDia((ClassDiagram) diagram);
		
	}

	@Override
	public void convert() {
		for( Map.Entry<String, Classe> valclass : dia.getClasMap().entrySet()){
			setSource("Class "+valclass.getValue().getName()+"\n");
		}
		
		for(Map.Entry<String, Iassociation> kaboom : dia.getAssociationmap().entrySet()){
			if(kaboom.getValue() instanceof Association){
				
				ArrayList<Classe> hey=((Association) kaboom.getValue()).getClas();
				
				for(Classe k : hey){
					System.out.println(k);
				}
				setSource(hey.get(0).getName()+"--"+hey.get(1).getName()+"\n");
			}
		}
		
		
	}

	public ClassDiagram getDia() {
		return dia;
	}

	public void setDia(ClassDiagram dia) {
		this.dia = dia;
	}

	public String getSource() {
		return "@startuml\n"+source+"@enduml\n";
	}

	public void setSource(String source) {
		this.source += source;
	}

	@Override
	public String getCode() {
		
		return "@startuml\n"+source+"@enduml\n";
	}

}
